<template>
  <div class="reportManage-container">
    <div class="reportManage-search">
      <span class="page-title">举报列表</span>
      <el-input placeholder="请输入搜索内容" v-model="keyWords" class="input-with-select search-keyword">
        <el-select v-model="select" slot="prepend" placeholder="请选择">
          <el-option label="举报人昵称" value="1"></el-option>
          <el-option label="被举报人昵称" value="2"></el-option>
        </el-select>
      </el-input>
      <el-button type="primary" size="small" icon="el-icon-search" @click="searchReport">搜索</el-button>
      <el-button type="info" size="small" class="search-keyword-reset" plain @click="resetSearch">重置</el-button>
    </div>

    <!--举报管理 table-->
    <div class="reportManage-table">
      <el-table ref="multipleTable" :data="reportData" border stripe fit v-loading="listLoading"
                :row-style="{height:'50px'}" :header-row-style="{height:'40px'}">
        <el-table-column label="id" width="80">
          <template slot-scope="scope">
            {{scope.row.id}}
          </template>
        </el-table-column>
        <el-table-column label="举报人昵称" width="180">
          <template slot-scope="scope">
            {{scope.row.userName}}
          </template>
        </el-table-column>
        <el-table-column label="被举报人昵称" width="180">
          <template slot-scope="scope">
            {{scope.row.toUserName}}
          </template>
        </el-table-column>
        <el-table-column label="违规对象id" width="100">
          <template slot-scope="scope">
            {{scope.row.moldId}}
          </template>
        </el-table-column>
        <el-table-column label="违规对象" width="100">
          <template slot-scope="scope">
            {{scope.row.moldType | changeReportObj}}
          </template>
        </el-table-column>
        <el-table-column label="举报原因" width="160">
          <template slot-scope="scope">
            {{scope.row.type}}
          </template>
        </el-table-column>
        <el-table-column label="是否已处理" width="100">
          <template slot-scope="scope">
            {{scope.row.status | changeDealStatus}}
          </template>
        </el-table-column>
        <el-table-column label="生成时间" width="160">
          <template slot-scope="scope">
            <span v-if="scope.row.time">{{scope.row.time | formatTime}}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" min-width="200" fixed="right">
          <template slot-scope="{row}">
            <el-dropdown size="mini" :split-button="true" type="primary" @click="handleLook(row)"
                         v-if="checkPermissionPoints(3) == 1">查看
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleEdit(row)" v-if="checkPermissionPoints(4) == 1">编辑
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :type="1" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
                  @pagination="getReportList"/>
    </div>

    <!--查看-->
    <el-dialog title="详细信息" :visible.sync="dialogLookVisible" width="960px" class="reportManage-dialog look-dialog">
      <el-form ref="form" label-width="140px" size="mini">
        <el-form-item label="举报人昵称：">
          <span>{{report.userName}}</span>
        </el-form-item>
        <el-form-item label="被举报人昵称：">
          <span>{{report.toUserName}}</span>
        </el-form-item>
        <el-form-item label="违规对象id：">
          <span>{{report.moldId}}</span>
        </el-form-item>
        <el-form-item label="举报原因：">
          <span>{{report.type}}</span>
        </el-form-item>
        <el-form-item label="举报内容：">
          <el-input type="textarea" style="width: 640px;" :autosize="{ minRows: 4, maxRows: 6 }"
                    v-html="report.details"></el-input>
        </el-form-item>
        <el-form-item label="是否已处理：">
          <span>{{report.status | changeDealStatus}}</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!--<el-button type="primary" style="width: 96px">编辑</el-button>-->
        <el-button size="small" style="width: 96px" @click="dialogLookVisible = false">取消</el-button>
      </div>
    </el-dialog>

    <!--新增/编辑-->
    <el-dialog title="编辑" :lock-scroll="true" :visible.sync="dialogEditVisible" width="960px"
               class="reportManage-dialog">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="auto" size="mini">
        <el-form-item label="举报人昵称：">
          <span>{{ruleForm.userName}}</span>
        </el-form-item>
        <el-form-item label="被举报人昵称：">
          <span>{{ruleForm.toUserName}}</span>
        </el-form-item>
        <el-form-item label="违规对象id：">
          <span>{{ruleForm.moldId}}</span>
        </el-form-item>
        <el-form-item label="举报原因：">
          <span>{{ruleForm.type}}</span>
        </el-form-item>
        <el-form-item label="举报内容：">
          <el-input type="textarea" style="width: 640px;" :autosize="{ minRows: 4, maxRows: 6 }"
                    v-html="ruleForm.details"></el-input>
        </el-form-item>
        <el-form-item label="是否已处理：" prop="status">
          <el-radio-group v-model="ruleForm.status">
            <el-radio :label="0">未处理</el-radio>
            <el-radio :label="1">已处理</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="success" style="width: 96px" @click="saveReport" :loading="sendLoad">保存
        </el-button>
        <el-button size="small" style="width: 96px" @click="dialogEditVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
  import Pagination from '@/components/Pagination';
  import {mapGetters} from 'vuex';
  import {permissionPoints} from '@/utils/permission';
  import {formatDate} from "@/utils/index";
  import {getInitReportList, getReportDetail, modifyReport} from "../../../api/social/social";

  export default {
    name: "reportManage",
    computed: {
      ...mapGetters([
        'points'
      ])
    },
    components: {
      Pagination
    },
    data() {
      return {
        total: 0,
        listQuery: {
          page: 1,
          limit: 20,
          userName: '',
          toUserName: ''
        },
        keyWords: '',
        select: '1',
        listLoading: false,
        dialogLookVisible: false,
        dialogEditVisible: false,
        reportData: [],
        report: {},
        ruleForm: {
          userName: '',
          toUserName: '',
          moldId: '',
          type: '',
          details: '',
          status: 0,
          id: ''
        },
        rules: {
          companyType: [
            {required: true, reportManage: '请输入企业类型', trigger: 'blur'}
          ],
          postName: [
            {required: true, reportManage: '请输入岗位名称', trigger: 'blur'}
          ]
        },
        sendLoad: false
      }
    },
    created() {
      this.getReportList();
    },
    methods: {
      checkPermissionPoints(type) {
        let pointObj = this.points.reportManage;
        return permissionPoints(type, pointObj);
      },
      searchReport() {//搜索
        if (this.keyWords == '' || this.keyWords == undefined) {
          return this.$message.info({message: '请输入搜索内容', duration: 1000});
        }
        this.listQuery.userName = '';
        this.listQuery.toUserName = '';
        if (this.select == 1) {
          this.listQuery.userName = this.keyWords;
        } else if (this.select == 2) {
          this.listQuery.toUserName = this.keyWords;
        }
        this.listQuery.page = 1;
        this.getReportList();
      },
      resetSearch() {
        this.select = '1';
        this.keyWords = '';
        this.listQuery.userName = '';
        this.listQuery.toUserName = '';
        this.listQuery.page = 1;
        this.getReportList();
      },
      getReportList() {
        this.listLoading = true;
        getInitReportList(this.listQuery).then((res) => {
          this.listLoading = false;
          let retObj = res;
          if (retObj.code == 0 && retObj.data != null) {
            const {items, totalRecord} = retObj.data;
            this.total = totalRecord;
            this.reportData = items;
          }
        }).catch(() => {
          this.listLoading = false;
        })
      },
      handleLook(row) {//详细信息
        this.dialogLookVisible = true;
        getReportDetail(row.id).then((res) => {
          let retObj = res;
          if (retObj.code == 0 && retObj.data != null) {
            this.report = retObj.data;
          }
        })
      },
      handleEdit(row) {//编辑
        this.dialogEditVisible = true;
        getReportDetail(row.id).then((res) => {
          let retObj = res;
          if (retObj.code == 0 && retObj.data != null) {
            this.ruleForm = retObj.data;
          }
        })
      },
      saveReport() {
        this.sendLoad = true;
        modifyReport(this.ruleForm.id, this.ruleForm.status).then((res) => {
          let retObj = res;
          this.sendLoad = false;
          if (retObj.code == 0 && retObj.data == 1) {
            this.ruleForm = {};
            this.dialogEditVisible = false;
            this.$message.success({message: '保存成功', duration: 2000});
            this.getReportList();
          } else {
            this.$message.error({message: '保存失败，请重试', duration: 2000});
          }
        }).catch(() => {
          this.sendLoad = false;
        })
      }
    },
    filters: {
      formatTime(time) {
        let date = new Date(time);
        return formatDate(date, 'yyyy-MM-dd hh:mm:ss');
      },
      changeReportObj(type) {//0 圈子 1评论
        if (type == 0) {
          return '圈子';
        } else if (type == 1) {
          return '评论';
        }
      },
      changeDealStatus(status) {//0未处理 1已处理
        if (status == 0) {
          return '未处理';
        } else if (status == 1) {
          return '已处理';
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .reportManage-container {
    .reportManage-search {
      display: flex;
      align-items: center;
      width: 100%;
      height: 80px;
      .page-title {
        padding-left: 18px;
        text-align: left;
        min-width: 160px;
        font-size: 18px;
        font-weight: bold;
        color: rgba(61, 68, 77, 1);
      }
      .search-keyword {
        margin-right: 24px;
        width: 470px;
        > > > .el-select .el-input {
          width: 140px;
        }
        > > > .el-input-group__prepend {
          background-color: #fff;
        }
      }
      .search-keyword-reset {
        margin-right: 36px;
      }
      .excel-inout-box {
        margin-left: auto;
        margin-right: 18px;
      }
    }

    .reportManage-table {
      width: 98%;
      margin-left: 18px;
      > > > .el-table td, .el-table th {
        padding: 6px 0px;
      }
      > > > .el-table__header th {
        padding: 0;
        height: 30px;
        line-height: 30px;
      }
      > > > .el-table__fixed-right {
        height: 100% !important;
      }
      > > > .el-table__column-filter-trigger {
        line-height: 28px;
        i {
          font-size: 18px;
        }
      }
      > > > .el-table__row .cell {
        display: flex;
        align-items: center;
      }
      > > > .el-table__header .has-gutter .cell {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
    }

    .reportManage-dialog > > > .el-dialog .el-dialog__header {
      display: flex;
      align-items: center;
      height: 48px;
      background: #F7F8FA;
      padding: 0px 0px 0px 12px;
      .el-dialog__headerbtn {
        top: 15px;
      }
    }
    .look-dialog > > > .el-form-item--mini.el-form-item, .el-form-item--small.el-form-item {
      margin-bottom: 0px;
    }
    .reportManage-dialog {
      font-size: 14px;
      color: #606266;
    }
    > > > .el-button {
      line-height: 1.2;
    }
  }
</style>
